package com.leet.meituan;

import com.leet.tree.TreeNode;

import java.util.*;

public class StoreManagement {
    static TreeMap<Integer,Integer> set = new TreeMap<>();
    static TreeSet<Integer> bound = new TreeSet<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        // 下一行以空格分开放在string数组里，用的时候要Integer.parseInt
        String[] s = sc.nextLine().split(" ");
        int[] arr = new int[n];
        int[] prefix = new int[n];
        bound.add(0);
        bound.add(n);

        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(s[i]);
            if (i == 0) {
                prefix[i] = arr[i];
            } else prefix[i] += prefix[i - 1] + arr[i];
        }
        set.put(prefix[n-1],0);
        String[] test = sc.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            int pos = Integer.parseInt(test[i]);
            Integer left = bound.lower(pos);
            Integer right = bound.higher(pos);
            if (left == null || right == null) {
                continue;
            }
            int tmp_sum = prefix[right-1]-prefix[left];
            set.remove(tmp_sum);
            set.put(prefix[right-1]-prefix[pos], set.getOrDefault(prefix[right-1]-prefix[pos],0)+1);
            set.put(prefix[pos-1]-prefix[left], set.getOrDefault(prefix[pos-1]-prefix[left],0)+1);
            System.out.println(set.lastKey());
        }

    }
}